#include "regx52.h"
#include "STC89C5xRC-rdp.h"
#include "datatype.h"
#include "bit.h"
#include "delay.h"

#include "sg90_micro_servo.h"

void setup(void)
{
	/* put your setup code here, to run once: */
	timer2_init();
	set_sg90_angle(ZERO_ANGLE);
}

void main(void)
{
	fp_32 angle = ZERO_ANGLE;
	uint_8 mark = FALSE;

	setup();

	while(TRUE) {
		/* put your main code here, to run repeatedly: */
		if (mark == FALSE)
			angle += 1;
		else
			angle -= 1;

		if (angle > MAX_SAFELY_ANGLE)
			mark = TRUE;
		if (angle < MIN_SAFELY_ANGLE)
			mark = FALSE;

		set_sg90_angle(angle);

		delay_xms(10);
	}
}